﻿
@using Blazor.Diagrams.Components
@using AntDesign
@using AntDesign.Core;
@using AntDesign.TableModels;
@using ERP.Workflow.Designer.BlazorUI.Components;      
@inject ToolBoxProvider ToolBoxProvider;

 <div 
    @onmousedown:stopPropagation="true"
    @onmousemove:stopPropagation="true"
    @onmouseup:stopPropagation="true"
    @onwheel:stopPropagation="true" 
    @onclick:stopPropagation="true"
    @ondrag:stopPropagation="true"
    @ondragover:stopPropagation="true"
    @ondrop:stopPropagation="true"
    @ondblclick:stopPropagation="true" >
    <Menu  Style="@Style" Class="@Class"     DefaultSelectedKeys=@(new[] { "sub1" })  DefaultOpenKeys=@(new[] { "sub1" }) Mode=MenuMode.Inline >
        @foreach(var tool in Tools)
        {
           <MenuItem Key="@tool.Name" >
               <div   draggable="true"  @ondragstart="(e) => DragStart(e, tool)"  > <Icon Type="@tool!.Icon" Theme="outline" Rotate="@tool!.Rotate"/>@tool.Title</div>
           </MenuItem>         
        }           
 </Menu>
 </div>
@code {
    // public event Action<object, ToolDragStartEventArgs>? OnDragStart;
    bool InlineCollapsed = true;
    [Parameter] public string? Style{ get; set; }
    [Parameter] public string? Class{ get; set; }
    [Parameter] public EventCallback<ToolDragStartEventArgs> OnDragStart{ get; set; }


    public List<ToolBoxItem> Tools = new List<ToolBoxItem>();
    protected override Task OnInitializedAsync()
    {
        Tools=ToolBoxProvider.Define();
        return base.OnInitializedAsync();
    }
    protected void DragStart(DragEventArgs e, ToolBoxItem item)
    {
        OnDragStart!.InvokeAsync(new ToolDragStartEventArgs { Data=item,DragEventArgs=e });
     
    }
    public class ToolDragStartEventArgs:DragEventArgs
    {
        public ToolBoxItem? Data{ get; set; }
        public DragEventArgs? DragEventArgs{ get; set; }
    }
}
